$(function () {
    $("#cla_datagrid").datagrid({
        fitColumns: true,
        fit: true,
        toolbar: '#cla_toolbar',
        url: '/claims/list.do',
        pagination: true,
        striped: true,
        rownumbers: true,
        singleSelect: true,
        columns: [[
            {title: '用户名', field: 'username',align:'center', width: '500'},
            {title: '真实姓名', field: 'realname' ,align:'center', width: '500'},
            {title: '电话', field: 'tel' ,align:'center', width: '500'},
            {title: '邮箱', field: 'email' ,align:'center', width: '500'},
            {
                title: '部门', field: 'dept' ,align:'center', width: '500', formatter: function (value, row, index) {
                    return value ? value.name : "";
                }
            },
            {title: '入职日期', field: 'hireDate' ,align:'center', width: '500'},
            {
                title: '状态', field: 'state' ,align:'center', width: '500', formatter: function (value, row, index) {
                    return value ? "<font color='green'>在职</font>" : "<font color='red'>离职</font>"
                }
            },
            {
                title: '管理员', field: 'admin' ,align:'center', width: '500', formatter: function (value, row, index) {
                    return value ? "<font color='green'>是</font>" : "<font color='red'>否</font>"
                }
            }
        ]]
    })

    var methodObj = {
        //刷新按钮
        reload: function () {
            $("#cla_datagrid").datagrid("reload");
        },
        query: function () {
            var keyword = $("#keyword").textbox("getValue");
            var beginDate = $("#beginDate").textbox("getValue");
            var endDate = $("#endDate").textbox("getValue");
            var qoDept = $("#qoDept").textbox("getValue");

            $("#cla_datagrid").datagrid('load', {
                beginDate: beginDate,
                endDate: endDate,
                deptId: qoDept
            });
        }
    }

    $("a[data-cmd]").click(function () {
        var cmd = $(this).data("cmd");
        methodObj[cmd](this);
    })

})

